<template>
  <div class="myTable">
    <div class="header">
      <slot name="header">
        <div>{{ title }}</div>
        <div><slot name="headerHand"> </slot></div>
      </slot>
    </div>
    <el-table
      :data="userList"
      border
      style="width: 100%"
      v-bind="treeMenuConfig"
    >
      <template v-if="showIndexColumn">
        <el-table-column
          type="index"
          align="center"
          width="80"
          label="序号"
        ></el-table-column>
      </template>
      <template v-for="item in columnList" :key="item.prop">
        <el-table-column v-bind="item" align="center" show-overflow-tooltip>
          <template v-slot:default="scope">
            <slot :name="item.slotName" :row="scope.row">
              {{ scope.row[item.prop] }}
            </slot>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <div class="footer">
      <slot name="footer"></slot>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'my-table',
  props: {
    userList: {
      type: Array,
      require: true
    },
    columnList: {
      type: Array,
      require: true
    },
    showIndexColumn: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    treeMenuConfig: {
      type: Object,
      default: () => ({})
    }
  },
  setup() {
    return {}
  }
})
</script>

<style lang="less" scoped>
.myTable {
  box-sizing: border-box;
  padding: 10px;
  background: #fff;
  .header {
    display: flex;
    justify-content: space-between;
    padding: 20px 0;
    font-size: 26px;
  }
}
</style>
